package demo3;

import demo1.MyArrayList;

import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        ArrayList<String> list2 = new ArrayList<>(list);
        list2.add("hhh");
        list2.add("hhh");
        list2.add("hhh");
        list.add("dzj");
        list.add("hzp");
        list.add("xrx");
        list.add("xx");
        list.add("lyy");
        list.add("lwm");
        list.add(1,"sb");
        System.out.println(list);
        list.addAll(4,list2);
        System.out.println(list);

        list.remove(1);
        System.out.println(list);

        System.out.println(list.get(6));
        list.set(6,"xxx");
        System.out.println(list);
        list.clear();
        System.out.println(list);
        list.addAll(list2);
        System.out.println(list);
        System.out.println(list.contains("hh"));

        System.out.println(list.indexOf("hhh"));
        System.out.println(list.lastIndexOf("hhh"));

        list.addAll(list2);
        list.addAll(list2);
        list.addAll(list2);
        System.out.println(list);

        list.clear();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        list.add("5");
        System.out.println(list);
        List<String> sub=list.subList(1,4);
        sub.set(0,"dzj");
        System.out.println(list);
        System.out.println(sub);

        List<String> newList=new ArrayList<>(list.subList(1,4));
        System.out.println(newList);
    }
}
